package day_2022_9_to_12.Day;

import java.util.ArrayList;
import java.util.List;

/**
 * @author haomin
 * @date 2022/10/15 10:15
 **/
public class Day43_1_Num1441_BuildArray {
    class Solution {
        public List<String> buildArray(int[] target, int n) {
            List<String> res = new ArrayList<>();
            int[] arr = new int[target[target.length-1]+1];
            for(int i = 0; i < target.length; ++i){
                arr[target[i]]++;
            }
            for(int i = 1; i < arr.length; ++i){
                if(arr[i] != 0){
                    res.add("Push");
                }else {
                    res.add("Push");
                    res.add("Pop");
                }
            }
            return res;
        }
    }
    // 方法二
    class Solution2 {
        public List<String> buildArray(int[] target, int n) {
            List<String> res = new ArrayList<>();
            int goal = 1;
            for(int i = 0; i < target.length;){
                if(target[i] > goal){
                    res.add("Push");
                    res.add("Pop");
                    goal++;
                }else{
                    res.add("Push");
                    goal++;
                    i++;
                }
            }
            return res;
        }
    }
}